const { getList: MGT, add: MA, select: MS,remove: MR, selectAll: MSA, removeSelect: MRS} = require('../model/adminGoods')

const getList = async (req, res, next) => {
  const { id, current, pagesize } = req.query

  const result = await MGT(id - 0, current, pagesize)
  res.send({
    message: '获取购物车列表成功',
    code: 1,
    yourParams: {
      msg: '这是你带来的参数, 我带回去给你看看 ^_^',
      id,
      current,
      pagesize
    },
    getResult: result
  })
}

const add = async (req, res, next) => {
  const { id} = req.body

  const result = await MA(id - 0, goodsId - 0)

  if (result === 0) return res.send({
    message: '加入购物车失败, 你给我的商品 id 不存在',
    code: 0,
    tips: `你传递给我的 'id' 是 : '${ id }' ^_^`
  })

  res.send({
    message: '加入购物车成功 ! 你太有钱了 ! O(∩_∩)O哈哈~',
    code: 1
  })
}

const select = async (req, res, next) => {
  const { goods_id } = req.body
  const result = await MS(goods_id - 0)
  if (result === 0) return res.send({
    message: '修改信息失败, 你没选中',
    code: 0,
    tips: `你传递给我的 'goods_id' 是 : '${ goods_id }' ^_^`
  })

  res.send({
    message: '修改购买信息成功',
    code: 1
  })
}


const remove = async (req, res, next) => {
  const { goods_id } = req.query
  const result = await MR(goods_id - 0)

  if (result === 0) return res.send({
    message: '删除商品失败, 你还没有购买这件商品哦',
    code: 0,
    tips: `你传递给我的 'goods_id' 是 : '${ goods_id }' ^_^`
  })

  res.send({
    message: '删除商品成功',
    code: 1
  })
}

const selectAll = async (req, res, next) => {
  const { id, type } = req.body

  await MSA(id - 0, type - 0)

  res.send({
    message: '修改全部商品购买信息成功',
    code: 1
  })
}

const removeSelect = async (req, res, next) => {
  const  id  = req.query.id || req.params.id || req.body.id

  await MRS(id - 0)

  res.send({
    message: '删除所有已选中商品成功',
    code: 1
  })
}



module.exports = {
  getList,
  add,
  select,
  remove,
  selectAll,
  removeSelect
}
